from manimlib import *

sys.path.append('.')
from customized import *


class p1(Scene):
    def construct(self):
        # self.camera.frame.save_state()
        # self.add(NumberPlane())
        # self.camera.frame.rotate(13*DEGREES,about_point=[0.0, 0.0, 1.0])
        t = 0.9
        horse = SVGMobject('./svgs/horse.svg').scale(0.3).set_stroke(width=1, color=BLACK).shift(UR * 0.5 * t)
        vg = VGroup()
        for i in range(8):
            for j in range(8):
                s = CustomizedSquare(1).shift(RIGHT * i + DOWN * j)
                if (i + j) % 2 == 0:
                    s.set_fill(GREY_C, 1)
                vg.add(s)
        vg.move_to(ORIGIN).scale(t)
        self.add(vg)
        self.add(horse,Text('收到',color=BLACK),Text('收到',color=BLACK,font='Consolas').shift(RIGHT))
        self.wait()


class p2(Scene):
    def construct(self):
        # self.camera.frame.save_state()
        # self.add(NumberPlane())
        # self.camera.frame.rotate(13*DEGREES,about_point=[0.0, 0.0, 1.0])
        t = 0.9
        horse = SVGMobject('./svgs/horse.svg').scale(0.3).set_stroke(width=1, color=BLACK).shift(UR * 0.5 * t)
        vg = VGroup()
        for i in range(8):
            for j in range(8):
                s = CustomizedSquare(1).shift(RIGHT * i + DOWN * j)
                if (i + j) % 2 == 0:
                    s.set_fill(GREY_C, 1)
                vg.add(s)
        vg.move_to(ORIGIN).scale(t)
        self.add(vg)
        self.add(horse)
        # p2
        s_red = CustomizedSquare(1).scale(t).shift(UR * 0.5 * t).set_fill(YELLOW, 1)
        s_LV = CustomizedSquare(1).scale(t).shift(UP * 3.5 * t + RIGHT * 0.5 * t).set_fill(LV, 1)
        s_JH = CustomizedSquare(1).scale(t).shift(UP * 2.5 * t + RIGHT * 0.5 * t).set_fill(JH, 1)
        s_BLUE = CustomizedSquare(1).scale(t).shift(UP * 1.5 * t + RIGHT * 0.5 * t).set_fill(BLUE, 1)
        self.add(s_LV, s_JH, s_BLUE, s_red, horse,
                 s_LV.copy().shift(DOWN * 2 * t + RIGHT * t),
                 s_JH.copy().shift(DOWN * 2 * t + RIGHT * t),
                 s_BLUE.copy().shift(UP * 2 * t + RIGHT * t),
                 s_red.copy().shift(UP * 2 * t + RIGHT * t),
                 )
        vg_8 = VGroup()
        for i in range(4):
            for j in range(2):
                s = CustomizedSquare().stretch(2, 1).shift(RIGHT * i * 2 + DOWN * j * 4).set_color(RED).set_stroke(
                    width=8)
                vg_8.add(s)
        vg_8.move_to(ORIGIN).scale(t)
        self.add(vg_8,
                 horse.copy().shift(UP * 2 * t + RIGHT * 1 * t),
                 )
        self.wait()


class p3(Scene):
    def construct(self):
        # self.camera.frame.save_state()
        # self.add(NumberPlane())
        # self.camera.frame.rotate(13*DEGREES,about_point=[0.0, 0.0, 1.0])
        grid = CustomizedSquare().set_fill(LV, 1).get_grid(3, 3, height=6, buff=0)
        self.add(grid, CustomizedSquare().set_fill(WHITE, 1))

class p4(Scene):
    def construct(self):
        # self.camera.frame.save_state()
        # self.add(NumberPlane())
        # self.camera.frame.rotate(13*DEGREES,about_point=[0.0, 0.0, 1.0])
        grid = CustomizedSquare().set_fill(RED, 1).get_grid(2, 4, height=4, buff=0)
        s1=CustomizedSquare().set_fill(JH,1).shift(UL)
        s2=CustomizedSquare().set_fill(YELLOW,1).shift(UR)
        s3=CustomizedSquare().set_fill(LV,1).shift(UR+RIGHT*2)
        self.add(grid,s1,s2,s3,
                 s1.copy().shift(DR*2+RIGHT*2),
                 s2.copy().shift(DL*2+LEFT*2),
                 s3.copy().shift(DL*2+LEFT*2),
                 )
